﻿package mortal.game.view.signUp.lineOn.item
{
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.signUp.lineOn.data.*;
    import mortal.mvc.core.*;

    public class LineOnCell extends GSprite
    {
        public var _bg:GImageBitmap;
        public var _timeName:GTextFiled;
        protected var _itemRoll:LineOnItemRollSp;
        protected var _txtRoll:LineOnTextRoll;
        private var _quesMark:SWFPlayer;
        protected var _hasGotPic:GBitmap;
        public var gotRewardFlag:Boolean = false;
        protected var _shikeEffect:SWFPlayer;
        private var _getRewardTipText:GTextFiled;
        private var _shikeTime:uint = 0;
        private var _info:Object;

        public function LineOnCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:TextFormat = null;
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.lineOnListCellBg, 0, 0, this);
            this._timeName = UIFactory.gTextField("", 0, 25, 154, 20, this);
            this._itemRoll = UIFactory.getUICompoment(LineOnItemRollSp);
            UIFactory.setObjAttri(this._itemRoll, 41, 82, -1, -1, this);
            this._txtRoll = UIFactory.getUICompoment(LineOnTextRoll);
            UIFactory.setObjAttri(this._txtRoll, 0, 211, -1, -1, this);
            this._itemRoll.addSynChild(this._txtRoll);
            this._quesMark = UIFactory.getUICompoment(SWFPlayer);
            this._quesMark.timeRate = 5;
            this._quesMark.move(80, 157);
            this._quesMark.load("AchievementQuest.swf", ModelType.NormalSwf, null);
            this.addChild(this._quesMark);
            this._quesMark.visible = false;
            this._hasGotPic = UIFactory.gBitmap(ImagesConst.lineOnGetRewardFlag, 87, 163, this);
            this._hasGotPic.visible = false;
            this._shikeEffect = UIFactory.getUICompoment(SWFPlayer);
            this._shikeEffect.timeRate = 5;
            this._shikeEffect.move(78, 116);
            this._shikeEffect.load("ArriundEffect_cheng_big.swf", ModelType.NormalSwf, null);
            this.addChild(this._shikeEffect);
            this._shikeEffect.visible = false;
            this._getRewardTipText = UIFactory.gTextField("", 0, 211, 154, 20, this);
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            this._timeName.defaultTextFormat = _loc_1;
            this._timeName.setTextFormat(_loc_1);
            _loc_1 = GlobalStyle.textFormatHong;
            _loc_1.align = TextFormatAlign.CENTER;
            this._getRewardTipText.defaultTextFormat = _loc_1;
            this._getRewardTipText.setTextFormat(_loc_1);
            this._getRewardTipText.visible = false;
            this._itemRoll.configEventListener(EventName.LineOnCellRollComplete, this.onRollCompleteHd);
            return;
        }// end function

        private function onCk(event:MouseEvent) : void
        {
            this.showSWF(false);
            var _loc_2:Object = {key:5, constValue:120201001, itemCode:400051020};
            this.rollItem(_loc_2, _loc_2.itemCode);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.gotRewardFlag = false;
            this._bg.dispose(param1);
            this._itemRoll.dispose(param1);
            this._txtRoll.dispose(param1);
            this._timeName.dispose(param1);
            this._bg = null;
            this._itemRoll = null;
            this._txtRoll = null;
            this._timeName = null;
            if (this._quesMark)
            {
                this._quesMark.filters = null;
                this._quesMark.dispose(param1);
            }
            this._quesMark = null;
            if (this._shikeEffect)
            {
                this._shikeEffect.stop();
                this._shikeEffect.dispose(param1);
            }
            this._shikeEffect = null;
            if (this._shikeTime > 0)
            {
                clearTimeout(this._shikeTime);
            }
            return;
        }// end function

        private function onRollCompleteHd(event:Event) : void
        {
            var _loc_3:Point = null;
            this._hasGotPic.visible = true;
            this._shikeEffect.visible = true;
            this._shikeEffect.play();
            this._shikeTime = setTimeout(this.clearShike, 5000);
            this._getRewardTipText.visible = false;
            MsgManager.showRollTipsMsg("" + Language.getString(71927));
            var _loc_2:* = Cache.instance.lineOn.getGodTips;
            if (_loc_2 && _loc_2 != "")
            {
                MsgManager.addTipText(_loc_2, MsgHistoryType.GetMsg);
                Cache.instance.lineOn.getGodTips = "";
            }
            if (this._itemRoll)
            {
                _loc_3 = this._itemRoll.localToGlobal(GameConst.yellowPoint);
                FlyToNavbarTool.flyBitmapOriginalToPack(this._itemRoll.getLastItemBm(), _loc_3);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.LineOnCellRightScrollOne));
            return;
        }// end function

        private function clearShike() : void
        {
            clearTimeout(this._shikeTime);
            this._shikeTime = 0;
            if (this._shikeEffect)
            {
                this._shikeEffect.visible = false;
                this._shikeEffect.stop();
            }
            return;
        }// end function

        public function initCell(param1:Object) : void
        {
            var _loc_3:uint = 0;
            this._info = param1;
            var _loc_2:* = LineOnRewardConfig.instance.getInfoKey(param1.constName);
            if (_loc_2 != -1)
            {
                this._timeName.text = Language.getStringByParam(71928, _loc_2);
                _loc_3 = int(Cache.instance.lineOn.rewardInfo.getReward[_loc_2]);
                if (_loc_3 != 0)
                {
                    this.gotRewardFlag = true;
                    this._hasGotPic.visible = true;
                    this._itemRoll.visible = true;
                    this._txtRoll.visible = true;
                    this._getRewardTipText.visible = false;
                    this.setShowItemAndName(param1, _loc_3);
                    this.showSWF(false);
                }
                else
                {
                    this.gotRewardFlag = false;
                    this._hasGotPic.visible = false;
                    this._getRewardTipText.visible = true;
                    this.showSWF(true);
                    this._itemRoll.visible = false;
                    this._txtRoll.visible = false;
                }
            }
            return;
        }// end function

        public function updateAfterGet(param1:Object) : Boolean
        {
            if (param1 == null || this._info == null)
            {
                return false;
            }
            var _loc_2:* = LineOnRewardConfig.instance.getConstName(param1.key);
            if (this._info.constName == _loc_2)
            {
                this.showSWF(false);
                this.gotRewardFlag = true;
                var _loc_3:Boolean = true;
                this._itemRoll.visible = true;
                var _loc_3:Boolean = true;
                this._txtRoll.visible = true;
                this.rollItem(param1, param1.itemCode);
                return true;
            }
            return false;
        }// end function

        private function setShowItemAndName(param1:Object, param2:int) : void
        {
            var _loc_3:* = LineOnRewardConfig.instance.getRollRandomItems(param1, param2, true);
            this._itemRoll.getRenders(_loc_3);
            this._itemRoll.stop();
            var _loc_4:* = LineOnRewardConfig.instance.getItemNameArrayByCodeArr(_loc_3);
            this._txtRoll.getRenders(_loc_4);
            this._txtRoll.stop();
            return;
        }// end function

        private function rollItem(param1:Object, param2:int) : void
        {
            this._getRewardTipText.visible = false;
            this._itemRoll.reset();
            this._txtRoll.reset();
            var _loc_3:* = Cache.instance.lineOn.ignorCk;
            var _loc_4:* = LineOnRewardConfig.instance.getRollRandomItems(param1, param2, _loc_3);
            this._itemRoll.getRenders(_loc_4);
            var _loc_5:* = LineOnRewardConfig.instance.getItemNameArrayByCodeArr(_loc_4);
            this._txtRoll.getRenders(_loc_5);
            if (_loc_3 == false)
            {
                this._itemRoll.star();
            }
            else
            {
                this._itemRoll.stop();
                this._txtRoll.stop();
                this.onRollCompleteHd(null);
            }
            return;
        }// end function

        public function updateContinueMinu(param1:int) : void
        {
            var _loc_2:TextFormat = null;
            if (this.gotRewardFlag)
            {
                this._getRewardTipText.visible = false;
            }
            else if (param1 <= 0)
            {
                _loc_2 = GlobalStyle.textFormatLv;
                _loc_2.align = TextFormatAlign.CENTER;
                this._getRewardTipText.defaultTextFormat = _loc_2;
                this._getRewardTipText.setTextFormat(_loc_2);
                this._getRewardTipText.text = "" + Language.getString(71929);
                if (this._quesMark)
                {
                    this._quesMark.filters = null;
                }
            }
            else
            {
                _loc_2 = GlobalStyle.textFormatHong;
                _loc_2.align = TextFormatAlign.CENTER;
                this._getRewardTipText.defaultTextFormat = _loc_2;
                this._getRewardTipText.setTextFormat(_loc_2);
                this._getRewardTipText.text = Language.getStringByParam(71930, param1);
                if (this._quesMark)
                {
                    this._quesMark.filters = [FilterConst.colorFilter2];
                }
            }
            return;
        }// end function

        public function hasGift(param1:int) : Boolean
        {
            var _loc_3:uint = 0;
            if (this._info == null)
            {
                return false;
            }
            var _loc_2:* = LineOnRewardConfig.instance.getInfoKey(this._info.constName);
            if (_loc_2 != -1)
            {
                this._timeName.text = Language.getStringByParam(71928, _loc_2);
                _loc_3 = int(Cache.instance.lineOn.rewardInfo.getReward[_loc_2]);
                if (_loc_3 != 0)
                {
                    return false;
                }
                if (param1 <= 0)
                {
                    return true;
                }
                return false;
            }
            return false;
        }// end function

        private function showSWF(param1:Boolean) : void
        {
            this._quesMark.visible = param1;
            if (param1)
            {
                if (this._quesMark)
                {
                    this._quesMark.play();
                }
            }
            else if (this._quesMark)
            {
                this._quesMark.stop();
            }
            return;
        }// end function

        private function canGetGift(param1:Object) : Boolean
        {
            return false;
        }// end function

    }
}
